#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>

int main()
{
  printf("\n");
  //----------needed variables----------
  
  int i,j;
  int n=50;
  char line1[50];
  char line2[50];
  char line3[50];
  char line4[50];
  char hex[2];
  char binary1[4];
  char binary2[4];
  char convHEX[2];
  
  //----------initialize input files----------

  FILE * fileIN;
  FILE * fileOUT;
  FILE * sramIN;
  FILE * sramOUT;
 
  fileIN=fopen("t2_input.txt", "r");
  fileOUT=fopen("t2_output.txt", "r");
  sramIN=fopen("mem_dump_01.txt", "r");
  sramOUT=fopen("mem_init_01.txt", "r");

  //----------check the input with the mem dump----------
  
  for(i=0;i<6;i++)		// skip the first 6 lines of mem dump
  {fgets(line1,n,sramIN);}
  
  for(i=0;i<5;i++)		// process addr 63-67
  {fgets(line1,n,sramIN);
   hex[0]=line1[3];             // get first hex value
   hex[1]=line1[4];             // get second hex value
  
   for(j=0;j<4;j++)		// put 8 digits as binary into variable
   {fgets(line2,n,fileIN);
    binary1[j]=line2[0];}
   for(j=0;j<4;j++)
   {fgets(line2,n,fileIN);
    binary2[j]=line2[0];}

   if(binary1[0]=='0')		// convert the first byte to hex
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='0';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='1';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='2';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='3';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='4';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='5';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='6';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='7';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='8';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='9';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='A';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='B';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='C';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='D';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='E';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='F';}}}}
   
   if(binary2[0]=='0')		// convert the second byte to hex
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='0';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='1';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
      {convHEX[1]='2';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='3';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='4';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='5';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
      {convHEX[1]='6';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='7';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='8';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='9';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
     {convHEX[1]='A';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='B';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='C';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='D';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
      {convHEX[1]='E';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='F';}}}}
   
   if (i==4)
   {convHEX[1]='0';}		// zero pad

   if(hex[0]!=convHEX[0])	// check if there is any difference
   {printf("%s\n", "mem_dump does not match input!");
    printf("Input_file: %s\nMem_dump: %s\n\n", convHEX, hex);
//    exit(1);
   }
   else if(hex[1]!=convHEX[1])	// check if there is any difference
   {printf("%s\n", "mem_dump does not match input!");
    printf("Input_file: %s\nMem_dump: %s\n\n", convHEX, hex);
//    exit(1);
   }
   else{}
  }
  
  for(i=0;i<85;i++)             // skip 80 lines of mem dump
  {fgets(line1,n,sramIN);}

  for(i=0;i<6;i++)             // skip 6 bits of input
  {fgets(line2,n,fileIN);}

  for(i=0;i<48;i++)		// process addr 255-302
  {fgets(line1,n,sramIN);
   hex[0]=line1[4];             // get first hex value
   hex[1]=line1[5];             // get second hex value
  
   for(j=0;j<4;j++)		// put 8 digits as binary into variable
   {fgets(line2,n,fileIN);
    binary1[j]=line2[0];}
   for(j=0;j<4;j++)
   {fgets(line2,n,fileIN);
    binary2[j]=line2[0];}

   if(binary1[0]=='0')		// convert the first byte to hex
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='0';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='1';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='2';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='3';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='4';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='5';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='6';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='7';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='8';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='9';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='A';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='B';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='C';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='D';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='E';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='F';}}}}
   
   if(binary2[0]=='0')		// convert the second byte to hex
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='0';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='1';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
      {convHEX[1]='2';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='3';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='4';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='5';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
      {convHEX[1]='6';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='7';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='8';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='9';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
     {convHEX[1]='A';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='B';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='C';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='D';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
      {convHEX[1]='E';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='F';}}}}
   
   if(hex[0]!=convHEX[0])	// check if there is any difference
   {printf("%s\n", "mem_dump does not match input!");
    printf("Input_file: %s\nMem_dump: %s\n\n", convHEX, hex);
//    exit(1);
   }
   else if(hex[1]!=convHEX[1])	// check if there is any difference
   {printf("%s\n", "mem_dump does not match input!");
    printf("Input_file: %s\nMem_dump: %s\n\n", convHEX, hex);
//    exit(1);
   }
   else{}
  }

  //----------success message----------

  printf("There were no differences between Input_file and Mem_dump!\n\n");

  //----------check the mem init with the output----------
    
  for(i=0;i<1;i++)		// skip the first line of mem init
  {fgets(line3,n,sramOUT);}

  for(i=0;i<5;i++)		// process addr 0-4
  {fgets(line3,n,sramOUT);
   hex[0]=line3[2];             // get first hex value
   hex[1]=line3[3];             // get second hex value
  
   for(j=0;j<4;j++)		// put 8 digits as binary into variable
   {fgets(line4,n,fileOUT);
    binary1[j]=line4[0];}
   for(j=0;j<4;j++)
   {fgets(line4,n,fileOUT);
    binary2[j]=line4[0];}

   if(binary1[0]=='0')		// convert the first byte to hex
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='0';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='1';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='2';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='3';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='4';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='5';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='6';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='7';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='8';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='9';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='A';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='B';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='C';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='D';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='E';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='F';}}}}
   
   if(binary2[0]=='0')		// convert the second byte to hex
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='0';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='1';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
      {convHEX[1]='2';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='3';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='4';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='5';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
      {convHEX[1]='6';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='7';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='8';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='9';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
     {convHEX[1]='A';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='B';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='C';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='D';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
      {convHEX[1]='E';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='F';}}}}

   if(hex[0]!=convHEX[0])	// check if there is any difference
   {printf("%s\n", "mem_init does not match output!");
    printf("Output_file: %s\nMem_init: %s\n\n", convHEX, hex);
    exit(1);
   }
   else if(hex[1]!=convHEX[1])	// check if there is any difference
   {printf("%s\n", "mem_init does not match output!");
    printf("Output_file: %s\nMem_init: %s\n\n", convHEX, hex);
    exit(1);
   }
   else{}
  }

  for(i=0;i<80;i++)		// process addr 127-158, 191-238
  {fgets(line3,n,sramOUT);
   hex[0]=line3[4];             // get first hex value
   hex[1]=line3[5];             // get second hex value
  
   for(j=0;j<4;j++)		// put 8 digits as binary into variable
   {fgets(line4,n,fileOUT);
    binary1[j]=line4[0];}
   for(j=0;j<4;j++)
   {fgets(line4,n,fileOUT);
    binary2[j]=line4[0];}

   if(binary1[0]=='0')		// convert the first byte to hex
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='0';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='1';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='2';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='3';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='4';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='5';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='6';}}}}
   if(binary1[0]=='0')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='7';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='8';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='9';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='A';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='0')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='B';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='0')
      {convHEX[0]='C';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='0')
     {if(binary1[3]=='1')
      {convHEX[0]='D';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='0')
      {convHEX[0]='E';}}}}
   if(binary1[0]=='1')
   {if(binary1[1]=='1')
    {if(binary1[2]=='1')
     {if(binary1[3]=='1')
      {convHEX[0]='F';}}}}
   
   if(binary2[0]=='0')		// convert the second byte to hex
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='0';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='1';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
      {convHEX[1]='2';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='3';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='4';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='5';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
      {convHEX[1]='6';}}}}
   if(binary2[0]=='0')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='7';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='8';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='9';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
     {convHEX[1]='A';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='0')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='B';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='0')
      {convHEX[1]='C';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='0')
     {if(binary2[3]=='1')
      {convHEX[1]='D';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='0')
      {convHEX[1]='E';}}}}
   if(binary2[0]=='1')
   {if(binary2[1]=='1')
    {if(binary2[2]=='1')
     {if(binary2[3]=='1')
      {convHEX[1]='F';}}}}
  
   if(hex[0]!=convHEX[0])	// check if there is any difference
   {printf("%s\n", "mem_init does not match output!");
    printf("Output_file: %s\nMem_init: %s\n\n", convHEX, hex);
    exit(1);
   }
   else if(hex[1]!=convHEX[1])	// check if there is any difference
   {printf("%s\n", "mem_init does not match output!");
    printf("Output_file: %s\nMem_init: %s\n\n", convHEX, hex);
    exit(1);
   }
   else{}
  }

  //----------success message----------

  printf("There were no differences between Output_file and Mem_init!\n\n");

  //----------close all files----------
  
  fclose(sramOUT);
  fclose(sramIN);
  fclose(fileOUT);
  fclose(fileIN);

  return(0);
}
